<?php

namespace app\admin\controller;
use think\Config;
use think\Loader;
use think\Db;
class Index extends Base{
    public function index(){
    	echo 111;
        return $this->fetch('/index');
    }
    /**
     * [indexPage 后台首页]
     * @return [type] [description]
     * @author [田建龙] [864491238@qq.com]
     */
    public function indexPage(){
        $info = array(
            'web_server' => $_SERVER['SERVER_SOFTWARE'],
            'onload'     => ini_get('upload_max_filesize'),
            'think_v'    => THINK_VERSION,
            'phpversion' => phpversion(),
        );
		$this->assign('month_order',100);
		$this->assign('month_money',100);
		$this->assign('tag',100);
		$this->assign('manu',10);
        $this->assign('info',$info);
        return $this->fetch('index');
    }


    /**
     * 清除缓存
     */
    public function clear() {
        if (delete_dir_file(CACHE_PATH) || delete_dir_file(TEMP_PATH)) {
            return json(['code' => 1, 'msg' => '清除缓存成功']);
        } else {
            return json(['code' => 0, 'msg' => '清除缓存失败']);
        }
    }
	/**
	 * 切换状态
	 */
	public function change_stat(){
		$data= request()->param();
		if(!isset($data['idname']) || empty($data['idname'])) $data['idname']='id';
		
		$status = Db::name($data['tab'])->where($data['idname'],$data['id'])->value($data['key']);//判断当前状态情况
        if($status==1){			//当前为开启
            $flag = Db::name($data['tab'])->where($data['idname'],$data['id'])->setField($data['key'],0);
            return json(['code' => 1, 'data' => $flag, 'msg' => '已禁止']);
        }else{
            $flag = Db::name($data['tab'])->where($data['idname'],$data['id'])->setField($data['key'],1);
            return json(['code' => 0, 'data' => $flag, 'msg' => '已开启']);
        }
	}
	public function change_stat2(){
		$data= request()->param();
		if(!isset($data['idname']) || empty($data['idname'])) $data['idname']='id';
		
		$status = Db::name($data['tab'])->where($data['idname'],$data['id'])->value($data['key']);//判断当前状态情况
        if($status==1){			//当前为开启
            $flag = Db::name($data['tab'])->where($data['idname'],$data['id'])->setField($data['key'],0);
            return json(['code' => 1, 'data' => $flag, 'msg' => '已开启']);
        }else{
            $flag = Db::name($data['tab'])->where($data['idname'],$data['id'])->setField($data['key'],1);
            return json(['code' => 0, 'data' => $flag, 'msg' => '已禁止']);
        }
	}
	/**
	 * 虚拟删除
	 */
	public function del(){
		$data=request()->param();
		$rel=Db::name($data['tab'])->where($data['idname'],$data['id'])->update(['del'=>1]);
		if(!$rel){
			return rel(0,'删除失败');
		}else{
			return rel(1,'删除成功');
		}
	}
	//真实删除数据
	public function truedel(){
		$data=request()->param();
		$rel=Db::name($data['tab'])->where($data['idname'],$data['id'])->delete();
		if(!$rel){
			return rel(0,'删除失败');
		}else{
			return rel(1,'删除成功');
		}
	}
	//更改某条为指定值数据
	public function update_val(){
		$data=request()->param();
		$rel=Db::name($data['tab'])->where($data['idname'],$data['id'])->update([$data['key']=>$data['val']]);
		if(!$rel){
			return rel(0,'更改失败');
		}else{
			return rel(1,'更改成功');
		}
	}
}
